package cn.piesat.scanning.business.xz.service.gseimpl;

import cn.hutool.core.date.DateUtil;
import cn.piesat.scanning.business.xz.service.BuildAlgorithmTaskService;
import cn.piesat.scanning.business.xz.single.AlgorithmTaskPathParam;
import cn.piesat.scanning.business.xz.single.AlgorithmTaskRuleParam;
import cn.piesat.scanning.dto.HtScanningMetadataDTO;
import cn.piesat.scanning.service.HtScanningMetadataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author Ming
 * @version 1.0
 * @description: TODO
 * @date 2023/12/18 13:48
 */
@Service
public class BuildTibet_Grass_RPPServiceImpl implements BuildAlgorithmTaskService {
    
    @Autowired
    private HtScanningMetadataService htScanningMetadataService;
    @Override
    public Map<String, Object> initAlgorithmParams(String adsType, String primaryFile, String filePath, AlgorithmTaskRuleParam taskRuleParam, AlgorithmTaskPathParam taskPathParam, Map<String, Integer> indexParams, String fileDate, String scanningPath,HtScanningMetadataDTO htScanningMetadataDTO) {
        Map<String, Object> algorithmParams = new HashMap<>();
        //草地FY3D_GPP对NDVI相关性分析
        String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
        String[] split = fileName.split("_");
        String region = split[2];
        String level = split[3];
        String satellite = split[4];
        String moduleIid = split[0];
        String productMode = split[8];
        String startTime = split[9];
        HtScanningMetadataDTO metadataDTO = htScanningMetadataService.findMetadataByParam(startTime, level, satellite,
                taskPathParam.getParameter05().replace("-", ""), region, productMode.replace("PO", "MO"), moduleIid, "TIFF");
        if (null == metadataDTO) {
            algorithmParams.put("parameter01", null);
        } else {
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            params.put("relFile", taskPathParam.getParameter02() + metadataDTO.getFilePath());
            params.put("auxPath", taskPathParam.getParameter03());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        }
        return algorithmParams;
    }
}
